package com.walk.zworld.ui.activity

import android.os.Build
import android.view.View
import android.widget.EditText
import androidx.annotation.RequiresApi
import com.walk.zworld.R
import com.walk.zworld.mvvm.viewModel.LoginActivityViewModel
import com.base.lib.base.utils.ext.view.showToast
import com.base.lib.base.view.BaseMvvmActivity

class RegisterActivity : BaseMvvmActivity<LoginActivityViewModel>() {

    override fun onBindViewModel(): Class<LoginActivityViewModel>  = LoginActivityViewModel::class.java

    override fun onBindLayout(): Int  = R.layout.activity_register

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun initData() {
//        setTop("注册")
        findViewById<View>(R.id.btn_register).setOnClickListener { register() }
    }

    override fun initView() {}

    private fun register() {
        val enterpriseName = findViewById<EditText>(R.id.et_login_id).text.toString().trim()
        val password1 = findViewById<EditText>(R.id.et_login_password1).text.toString().trim()
        val password2 = findViewById<EditText>(R.id.et_login_password2).text.toString().trim()
        when {
            enterpriseName == "" -> "账号不能为空".showToast()
            password1 == "" -> "密码不能为空".showToast()
            password1 != password2 -> "两次密码不一致".showToast()
            else -> {
                mViewModel.register(enterpriseName, password1, password2).observe(this) {
                    finish()
                }
            }
        }
    }
}